<!--  -->
<template>
  <div class="order_statistics">
    <div class="title">
      销售统计
      <span class="sub_title">{{ timeModule.start }}-{{ timeModule.end }}</span>
      <span class="button">
        <el-button size="mini" @click="weekFn">周</el-button>
        <el-button size="mini" @click="monthFn">月</el-button>
        <el-button size="mini" @click="yearFn">年</el-button>
      </span>
      <el-row
        class="table"
      >
        <el-col class="option" :span="12"><Ranking /></el-col>
        <el-col class="option" :span="12"><Scattergram /></el-col>
      </el-row>
    </div>

  </div>
</template>

<script>
import dayjs from '@/utils/dayjs'
// 导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
import Ranking from './Ranking.vue'
import Scattergram from './Scattergram.vue'
export default {
  name: 'OrderStatistics',
  components: {
    Ranking, Scattergram
  },
  props: {
    timeModule: {
      type: Object,
      required: true
    }
  },
  data() {
    return {

    }
  },
  // 监听属性 类似于data概念
  computed: {},
  // 监控data中的数据变化
  watch: {},
  // 生命周期 - 创建完成（可以访问当前this实例）
  created() {

  },
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {

  },

  beforeCreate() {}, // 生命周期 - 创建之前
  beforeMount() {}, // 生命周期 - 挂载之前
  beforeUpdate() {}, // 生命周期 - 更新之前
  updated() {}, // 生命周期 - 更新之后
  beforeDestroy() {}, // 生命周期 - 销毁之前
  destroyed() {}, // 生命周期 - 销毁完成
  activated() {},
  // 方法集合
  methods: {
    weekFn() {
      this.$store.dispatch('home/salesFigures', {
        collectType: 1,
        start: dayjs().subtract(7, 'day').format('YYYY-MM-DD'),
        end: dayjs().format('YYYY-MM-DD')
      })
      this.$store.dispatch('home/regionCollect', {
        start: dayjs().subtract(7, 'day').format('YYYY-MM-DD'),
        end: dayjs().format('YYYY-MM-DD')
      })
      // console.log(dayjs().day(0).format('YYYY-MM-DD'))
      // console.log(this.$store.state.home.salesFigures.xAxis)
      // console.log(this.$store.state.home.salesFigures.series)

      // console.log(dayjs().subtract(7, 'day').format('YYYY-MM-DD'))
    },
    monthFn() {
      this.$store.dispatch('home/salesFigures', {
        collectType: 1,
        start: dayjs().startOf('month').format('YYYY-MM-DD'),
        end: dayjs().format('YYYY-MM-DD')
      })
      this.$store.dispatch('home/regionCollect', {
        start: dayjs().startOf('month').format('YYYY-MM-DD'),
        end: dayjs().format('YYYY-MM-DD')
      })
      // console.log(dayjs().startOf('month').format('YYYY-MM-DD'))
      // console.log(this.$store.state.home.salesFigures.xAxis)
      // console.log(this.$store.state.home.salesFigures.series)
    },
    yearFn() {
      this.$store.dispatch('home/salesFigures', {
        collectType: 2,
        start: dayjs().startOf('year').format('YYYY-MM-DD'),
        end: dayjs().format('YYYY-MM-DD')
      })
      this.$store.dispatch('home/regionCollect', {
        start: dayjs().startOf('year').format('YYYY-MM-DD'),
        end: dayjs().format('YYYY-MM-DD')
      })
      // console.log(dayjs().startOf('year').format('YYYY-MM-DD'))
      // console.log(this.$store.state.home.salesFigures.xAxis)
      // console.log(this.$store.state.home.salesFigures.series)
    }
  } // 如果页面有keep-alive缓存功能，这个函数会触发
}
// likede/api/order-service/report/amountCollect/1/2022-09-01/2022-09-28  天/周/月
// series:[365560, 246879, 88474, 158886, 286355, 142408, 232494, 554876, 557338, 201177, 236031, 305915, 553091,…]
// xAxis:["2022-09-01", "2022-09-02", "2022-09-03", "2022-09-04", "2022-09-05", "2022-09-06", "2022-09-07",…]

// likede/api/order-service/report/regionCollect/2022-09-01/2022-09-28
// {series: [7457580, 1348956],xAxis: ["北京平西府街道", "霍营街道"]}

</script>
<style scoped lang='scss'>
.title{
  margin-top: -10px;
  height: 34px;
  line-height: 34px;
  min-height: 280px;
}
.button{
    display: flex;
    float: right;
    width: 160px;
    padding: 3px 8px;
    height: 34px;
    background: #f8fafd;
    border-radius: 10px;
}
.el-button{
  flex:1;
  border: none !important;
  height: 100%;
  background: #f8fafd;
  color: #999;

}
.el-button:focus, .el-button:hover {
  background:#fff;
  color: #000;
}
.grid_content{
  height: 20px;
  line-height: 20px;
  margin-top: 15px;
  font-size: 12px;
  color: #999;
}
.good_sname{
  font-size: 14px;
  color: #000;
}
.goods_num{
  float: right;
}
.num_text{
    padding-top: 10px;
    height: 50px;
    font-size: 36px;
    font-weight: 600;
    line-height: 50px;
    color: #ed635e;
    text-shadow: 2px 4px 7px rgb(85 132 255 / 50%);
}
.text{
    height: 17px;
    width: 100%;
    margin-top: 3px;
    font-size: 12px;
    font-family: PingFangSC-Regular,PingFang SC;
    font-weight: 400;
    color: #ed635e;
    line-height: 17px;
}
.sub_title{
    margin-left: 10px;
    font-size: 12px;
    font-family: PingFangSC-Regular,PingFang SC;
    font-weight: 400;
    color: #999;
}
.order_statistics{
  padding: 25px;
  width: 100%;
  height: 70% !important;
  background: #fff;
  border-radius: 20px;
  height: calc(20vh - 24px);
  min-height: 166px;
}
</style>
